// pages/welcome/welcome.js 

/* 欢迎页-轮播显示图 */

var wxNetwork = require("../../utils/network.js");
var wxURL = require("../../utils/requestURL.js");

Page({
  data: {
    currentYear: '',
    imgUrls: [
      '/images/welcome/welcome1.png',
      '/images/welcome/welcome2.png',
      '/images/welcome/welcome3.png'
    ],
    waterUsers:[]
  },

  onLoad: function() {
    
    var that = this;

    that.getWaterUsers();

    var date = new Date(); //获取系统当前时间
    var myDate = date.getFullYear(); //设置格式为YYYY
    that.setData({
      currentYear: myDate
    });
  },
 
  /** 获取用水户 */
  getWaterUsers:function(){
    
    var that = this;

    var header = { 'Access-Token': wx.getStorageSync('token')};
    wxNetwork.getRequest(wxURL.get_queryUsers_URL, {}, header, function (dict){
      that.setData({
        waterUsers: dict.content.waterUsers
      });
    },
      function (dict){

    }, 
      function (dict) {

    })
  },

  buttonClickEvent:function(){
    
    //本地保存：isFirst作为首次使用
    wx.setStorageSync('isFirst', true);

    if (this.data.waterUsers.length == 0) { //用水户无数据，到认证
       wx.navigateTo({
         url: '../userIdent/userIdent',
       })
    }
    else { //用水户有数据，到首页
      wx.switchTab({
        url: '../home/home',
      })
    }
  }
})